import { Observable } from "rxjs";


export const demo = () => {
  // 最基础的创建一个立刻执行的Observable
  const observable = new Observable((subscriber) => {
    subscriber.next(1);
    subscriber.next(2);

    setTimeout(() => {
      subscriber.next(4);
      subscriber.complete();
      subscriber.error("this is error");
    });
  });

  observable.subscribe({
    next(value) {
      console.log(value);
    },
    complete() {
      console.log("componetaaa.....");
    },
    error(err) {
      console.log(err);
    },
  });
};
